package logic

import (
	"context"
	"mini/model/redis"

	"mini/userrpc/internal/svc"
	"mini/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProjectRankLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProjectRankLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProjectRankLogic {
	return &ProjectRankLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProjectRankLogic) ProjectRank(in *userrpc.ProjectRankRequest) (*userrpc.ProjectRankResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Rdb.ZRevRangeWithScores("ProjectLike", 0, 9)

	var sli []*userrpc.ProjectRank
	for _, i2 := range scores.Val() {
		one := userrpc.ProjectRank{
			Score: float32(i2.Score),
			Id:    i2.Member.(string),
		}
		sli = append(sli, &one)
	}

	return &userrpc.ProjectRankResponse{ProjectRank: sli}, nil
}
